--- 模块功能：设备参数存储功能
-- @author openLuat
-- @module nvm.testNvm
-- @license MIT
-- @copyright openLuat
-- @release 2018.03.27
module(..., package.seeall)

require "config"
require "nvm"
require "logGenerator"
require "mqttOutMsg"
local slen, logInfo, errInfo, sysTime = string.len, "", "", ""
nvm.init("config.lua", true)

-- 预警设备参数设置-身份判别
local function containClientsOrNot(clients)
    do
        local containResult = false
        for i = 1, #clients do
            if clients[i] == nvm.get("info")[1] then
                containResult = true
            end
        end
        return containResult
    end
end

-- 获取设备参数
local function getParameters()
    local appName, version, longitude, latitude, cloud, lock, openTime,
          closeTime, updateUrl, versionUrl, broker, ntpServer, delayTime,
          centerName, intensity, magnitude, centerIntensity, countDown,
          alertSound, alertLight, emergencyLamp, relay, adVolume, alertVolume,
          intensityReturn, adUpdateUrl, orgName, makeVideo, uploadVideoUrl,
          broadcast, broadcastUrl, h24, enable433, autoUpdateLog,
          alertDisplayMode, color1, color2, color3, color4, luminance, hz,
          autoCheckTime, regCenter, lockPsw, receive, replayLockPsw,
          enableRF433, enableAcc, enableTF, enableHandset, hideBattery,
          brightnessPositive, clientName, updateRate, memsIp, stations, move,
          rotate, info, centerConfig, enableRealKey, blueLimit, yellowLimit,
          orangeLimit, redLimit, afterSecond, sourceText, blueGuide,
          yellowGuide, orangeGuide, redGuide, exerciseText, enableMax10,
          cancelCount, fastCount, carouselCount, master, masterPair = nvm.get(
                                                                          "appName"),
                                                                      nvm.get(
                                                                          "version"),
                                                                      nvm.get(
                                                                          "longitude"),
                                                                      nvm.get(
                                                                          "latitude"),
                                                                      nvm.get(
                                                                          "cloud"),
                                                                      nvm.get(
                                                                          "lock"),
                                                                      nvm.get(
                                                                          "openTime"),
                                                                      nvm.get(
                                                                          "closeTime"),
                                                                      nvm.get(
                                                                          "updateUrl"),
                                                                      nvm.get(
                                                                          "versionUrl"),
                                                                      nvm.get(
                                                                          "broker"),
                                                                      nvm.get(
                                                                          "ntpServer"),
                                                                      nvm.get(
                                                                          "delayTime"),
                                                                      nvm.get(
                                                                          "centerName"),
                                                                      nvm.get(
                                                                          "intensity"),
                                                                      nvm.get(
                                                                          "magnitude"),
                                                                      nvm.get(
                                                                          "centerIntensity"),
                                                                      nvm.get(
                                                                          "countDown"),
                                                                      nvm.get(
                                                                          "alertSound"),
                                                                      nvm.get(
                                                                          "alertLight"),
                                                                      nvm.get(
                                                                          "emergencyLamp"),
                                                                      nvm.get(
                                                                          "relay"),
                                                                      nvm.get(
                                                                          "adVolume"),
                                                                      nvm.get(
                                                                          "alertVolume"),
                                                                      nvm.get(
                                                                          "intensityReturn"),
                                                                      nvm.get(
                                                                          "adUpdateUrl"),
                                                                      nvm.get(
                                                                          "orgName"),
                                                                      nvm.get(
                                                                          "makeVideo"),
                                                                      nvm.get(
                                                                          "uploadVideoUrl"),
                                                                      nvm.get(
                                                                          "broadcast"),
                                                                      nvm.get(
                                                                          "broadcastUrl"),
                                                                      nvm.get(
                                                                          "h24"),
                                                                      nvm.get(
                                                                          "enable433"),
                                                                      nvm.get(
                                                                          "autoUpdateLog"),
                                                                      nvm.get(
                                                                          "alertDisplayMode"),
                                                                      nvm.get(
                                                                          "color1"),
                                                                      nvm.get(
                                                                          "color2"),
                                                                      nvm.get(
                                                                          "color3"),
                                                                      nvm.get(
                                                                          "color4"),
                                                                      nvm.get(
                                                                          "luminance"),
                                                                      nvm.get(
                                                                          "hz"),
                                                                      nvm.get(
                                                                          "autoCheckTime"),
                                                                      nvm.get(
                                                                          "regCenter"),
                                                                      nvm.get(
                                                                          "lockPsw"),
                                                                      nvm.get(
                                                                          "receive"),
                                                                      nvm.get(
                                                                          "replayLockPsw"),
                                                                      nvm.get(
                                                                          "enableRF433"),
                                                                      nvm.get(
                                                                          "enableAcc"),
                                                                      nvm.get(
                                                                          "enableTF"),
                                                                      nvm.get(
                                                                          "enableHandset"),
                                                                      nvm.get(
                                                                          "hideBattery"),
                                                                      nvm.get(
                                                                          "brightnessPositive"),
                                                                      nvm.get(
                                                                          "clientName"),
                                                                      nvm.get(
                                                                          "updateRate"),
                                                                      nvm.get(
                                                                          "memsIp"),
                                                                      nvm.get(
                                                                          "stations"),
                                                                      nvm.get(
                                                                          "move"),
                                                                      nvm.get(
                                                                          "rotate"),
                                                                      nvm.get(
                                                                          "info"),
                                                                      nvm.get(
                                                                          "centerConfig"),
                                                                      nvm.get(
                                                                          "enableRealKey"),
                                                                      nvm.get(
                                                                          "blueLimit"),
                                                                      nvm.get(
                                                                          "yellowLimit"),
                                                                      nvm.get(
                                                                          "orangeLimit"),
                                                                      nvm.get(
                                                                          "redLimit"),
                                                                      nvm.get(
                                                                          "afterSecond"),
                                                                      nvm.get(
                                                                          "sourceText"),
                                                                      nvm.get(
                                                                          "blueGuide"),
                                                                      nvm.get(
                                                                          "yellowGuide"),
                                                                      nvm.get(
                                                                          "orangeGuide"),
                                                                      nvm.get(
                                                                          "redGuide"),
                                                                      nvm.get(
                                                                          "exerciseText"),
                                                                      nvm.get(
                                                                          "enableMax10"),
                                                                      nvm.get(
                                                                          "cancelCount"),
                                                                      nvm.get(
                                                                          "fastCount"),
                                                                      nvm.get(
                                                                          "carouselCount"),
                                                                      nvm.get(
                                                                          "master"),
                                                                      nvm.get(
                                                                          "masterPair")
    return appName, version, longitude, latitude, cloud, lock, openTime,
           closeTime, updateUrl, versionUrl, broker, ntpServer, delayTime,
           centerName, intensity, magnitude, centerIntensity, countDown,
           alertSound, alertLight, emergencyLamp, relay, adVolume, alertVolume,
           intensityReturn, adUpdateUrl, orgName, makeVideo, uploadVideoUrl,
           broadcast, broadcastUrl, h24, enable433, autoUpdateLog,
           alertDisplayMode, color1, color2, color3, color4, luminance, hz,
           autoCheckTime, regCenter, lockPsw, receive, replayLockPsw,
           enableRF433, enableAcc, enableTF, enableHandset, hideBattery,
           brightnessPositive, clientName, updateRate, memsIp, stations, move,
           rotate, info, centerConfig, enableRealKey, blueLimit, yellowLimit,
           orangeLimit, redLimit, afterSecond, sourceText, blueGuide,
           yellowGuide, orangeGuide, redGuide, exerciseText, enableMax10,
           cancelCount, fastCount, carouselCount, master, masterPair
end

-- 设备参数操作：通过mqtt远程获取设备参数，更改设备参数后，通过mqtt下发到设备并存储参数
function equipmentParametersRead(tjsondata)
    local clients, tClock = tjsondata["clients"], os.date("*t")
    sysTime = string.format("%04d-%02d-%02d %02d:%02d:%02d", tClock.year,
                            tClock.month, tClock.day, tClock.hour, tClock.min,
                            tClock.sec)
    if containClientsOrNot(clients) then
        -- config参数
        local appName, version, longitude, latitude, cloud, lock, openTime,
              closeTime, updateUrl, versionUrl, broker, ntpServer, delayTime,
              centerName, intensity, magnitude, centerIntensity, countDown,
              alertSound, alertLight, emergencyLamp, relay, adVolume,
              alertVolume, intensityReturn, adUpdateUrl, orgName, makeVideo,
              uploadVideoUrl, broadcast, broadcastUrl, h24, enable433,
              autoUpdateLog, alertDisplayMode, color1, color2, color3, color4,
              luminance, hz, autoCheckTime, regCenter, lockPsw, receive,
              replayLockPsw, enableRF433, enableAcc, enableTF, enableHandset,
              hideBattery, brightnessPositive, clientName, updateRate, memsIp,
              stations, move, rotate, info, centerConfig, enableRealKey,
              blueLimit, yellowLimit, orangeLimit, redLimit, afterSecond,
              sourceText, blueGuide, yellowGuide, orangeGuide, redGuide,
              exerciseText, enableMax10, cancelCount, fastCount, carouselCount,
              master, masterPair = getParameters()
        local configParameter1 = "{" .. "\"regCenter\"" .. ":" .. "\"" ..
                                     tostring(regCenter) .. "\"" .. "," ..
                                     "\"rotate\"" .. ":" .. "\"" .. rotate ..
                                     "\"" .. "," .. "\"autoCheckTime\"" .. ":" ..
                                     "\"" .. autoCheckTime .. "\"" .. "," ..
                                     "\"lockPsw\"" .. ":" .. "\"" .. lockPsw ..
                                     "\"" .. "," .. "\"color3\"" .. ":" .. "\"" ..
                                     color3 .. "\"" .. "," .. "\"color4\"" ..
                                     ":" .. "\"" .. color4 .. "\"" .. "," ..
                                     "\"cloud\"" .. ":" .. "\"" ..
                                     tostring(cloud) .. "\"" .. "," ..
                                     "\"color1\"" .. ":" .. "\"" .. color1 ..
                                     "\"" .. "," .. "\"color2\"" .. ":" .. "\"" ..
                                     color2 .. "\"" .. "," .. "\"hz\"" .. ":" ..
                                     "\"" .. hz .. "\"" .. "," ..
                                     "\"updateRate\"" .. ":" .. "\"" ..
                                     updateRate .. "\"" .. "," ..
                                     "\"centerIntensity\"" .. ":" .. "\"" ..
                                     tostring(centerIntensity) .. "\"" .. "," ..
                                     "\"enableHandset\"" .. ":" .. "\"" ..
                                     tostring(enableHandset) .. "\"" .. "," ..
                                     "\"adUpdateUrl\"" .. ":" .. "\"" ..
                                     adUpdateUrl .. "\"" .. "," ..
                                     "\"longitude\"" .. ":" .. "\"" ..
                                     tostring(longitude) .. "\"" .. "," ..
                                     "\"brightnessPositive\"" .. ":" .. "\"" ..
                                     tostring(brightnessPositive) .. "\"" .. "," ..
                                     "\"orgName\"" .. ":" .. "\"" .. orgName ..
                                     "\"" .. "," .. "\"enableAcc\"" .. ":" ..
                                     "\"" .. tostring(enableAcc) .. "\"" .. "," ..
                                     "\"h24\"" .. ":" .. "\"" .. tostring(h24) ..
                                     "\"" .. "," .. "\"stations\"" .. ":" ..
                                     "\"" .. stations .. "\"" .. "," ..
                                     "\"version\"" .. ":" .. "\"" .. version ..
                                     "\"" .. "," .. "\"enableRF433\"" .. ":" ..
                                     "\"" .. tostring(enableRF433) .. "\"" ..
                                     "," .. "\"updateUrl\"" .. ":" .. "\"" ..
                                     updateUrl .. "\"" .. "," ..
                                     "\"centerName\"" .. ":" .. "\"" ..
                                     centerName .. "\"" .. "," ..
                                     "\"uploadVideoUrl\"" .. ":" .. "\"" ..
                                     uploadVideoUrl .. "\"" .. "," ..
                                     "\"broadcast\"" .. ":" .. "\"" ..
                                     tostring(broadcast) .. "\"" .. "," ..
                                     "\"broadcastUrl\"" .. ":" .. "\"" ..
                                     broadcastUrl .. "\"" .. "," ..
                                     "\"luminance\"" .. ":" .. "\"" ..
                                     tostring(luminance) .. "\""
        local configParameter2 = "," .. "\"emergencyLamp\"" .. ":" ..
                                     tostring(emergencyLamp) .. "," ..
                                     "\"clientName\"" .. ":" .. "\"" ..
                                     clientName .. "\"" .. "," .. "\"latitude\"" ..
                                     ":" .. "\"" .. tostring(latitude) .. "\"" ..
                                     "," .. "\"memsIp\"" .. ":" .. "\"" ..
                                     memsIp .. "\"" .. "," ..
                                     "\"alertDisplayMode\"" .. ":" ..
                                     tostring(alertDisplayMode) .. "," ..
                                     "\"adVolume\"" .. ":" .. "\"" ..
                                     tostring(adVolume) .. "\"" .. "," ..
                                     "\"enableTF\"" .. ":" .. "\"" ..
                                     tostring(enableTF) .. "\"" .. "," ..
                                     "\"alertSound\"" .. ":" ..
                                     tostring(alertSound) .. "," ..
                                     "\"closeTime\"" .. ":" .. "\"" .. closeTime ..
                                     "\"" .. "," .. "\"magnitude\"" .. ":" ..
                                     "\"" .. tostring(magnitude) .. "\"" .. "," ..
                                     "\"makeVideo\"" .. ":" .. "\"" ..
                                     tostring(makeVideo) .. "\"" .. "," ..
                                     "\"countDown\"" .. ":" ..
                                     tostring(countDown) .. "," ..
                                     "\"ntpServer\"" .. ":" .. "\"" .. ntpServer ..
                                     "\"" .. "," .. "\"openTime\"" .. ":" ..
                                     "\"" .. openTime .. "\"" .. "," ..
                                     "\"alertVolume\"" .. ":" .. "\"" ..
                                     tostring(alertVolume) .. "\"" .. "," ..
                                     "\"autoUpdateLog\"" .. ":" .. "\"" ..
                                     tostring(autoUpdateLog) .. "\"" .. "," ..
                                     "\"intensityReturn\"" .. ":" .. "\"" ..
                                     tostring(intensityReturn) .. "\"" .. "," ..
                                     "\"receive\"" .. ":" .. "\"" ..
                                     tostring(receive) .. "\"" .. "," ..
                                     "\"move\"" .. ":" .. "\"" .. move .. "\"" ..
                                     "," .. "\"appName\"" .. ":" .. "\"" ..
                                     appName .. "\"" .. "," .. "\"relay\"" ..
                                     ":" .. tostring(relay) .. "," ..
                                     "\"enable433\"" .. ":" .. "\"" ..
                                     tostring(enable433) .. "\"" .. "," ..
                                     "\"broker\"" .. ":" .. "\"" .. broker ..
                                     "\"" .. "," .. "\"intensity\"" .. ":" ..
                                     "\"" .. tostring(intensity) .. "\"" .. "," ..
                                     "\"alertLight\"" .. ":" ..
                                     tostring(alertLight) .. "," ..
                                     "\"delayTime\"" .. ":" .. "\"" .. delayTime ..
                                     "\"" .. "," .. "\"enableRealKey\"" .. ":" ..
                                     "\"" .. tostring(enableRealKey) .. "\"" ..
                                     "," .. "\"hideBattery\"" .. ":" .. "\"" ..
                                     tostring(hideBattery) .. "\"" .. "," ..
                                     "\"replayLockPsw\"" .. ":" .. "\"" ..
                                     replayLockPsw .. "\""
        local configParameter3 = "," .. "\"blueLimit\"" .. ":" .. "\"" ..
                                     tostring(blueLimit) .. "\"" .. "," ..
                                     "\"yellowLimit\"" .. ":" .. "\"" ..
                                     tostring(yellowLimit) .. "\"" .. "," ..
                                     "\"orangeLimit\"" .. ":" .. "\"" ..
                                     tostring(orangeLimit) .. "\"" .. "," ..
                                     "\"alertDisplayMode\"" .. ":" ..
                                     tostring(alertDisplayMode) .. "," ..
                                     "\"redLimit\"" .. ":" .. "\"" ..
                                     tostring(redLimit) .. "\"" .. "," ..
                                     "\"afterSecond\"" .. ":" .. "\"" ..
                                     tostring(afterSecond) .. "\"" .. "," ..
                                     "\"sourceText\"" .. ":" .. "\"" ..
                                     sourceText .. "\"" .. "," ..
                                     "\"blueGuide\"" .. ":" .. "\"" .. blueGuide ..
                                     "\"" .. "," .. "\"yellowGuide\"" .. ":" ..
                                     "\"" .. yellowGuide .. "\"" .. "," ..
                                     "\"orangeGuide\"" .. ":" .. "\"" ..
                                     orangeGuide .. "\"" .. "," ..
                                     "\"redGuide\"" .. ":" .. "\"" .. redGuide ..
                                     "\"" .. "," .. "\"exerciseText\"" .. ":" ..
                                     "\"" .. exerciseText .. "\"" .. "," ..
                                     "\"enableMax10\"" .. ":" .. "\"" ..
                                     tostring(enableMax10) .. "\"" .. "," ..
                                     "\"cancelCount\"" .. ":" .. "\"" ..
                                     tostring(cancelCount) .. "\"" .. "," ..
                                     "\"fastCount\"" .. ":" .. "\"" ..
                                     tostring(fastCount) .. "\"" .. "," ..
                                     "\"carouselCount\"" .. ":" .. "\"" ..
                                     tostring(carouselCount) .. "\"" .. "," ..
                                     "\"master\"" .. ":" .. "\"" .. master ..
                                     "\"" .. "," .. "\"masterPair\"" .. ":" ..
                                     "\"" .. masterPair .. "\"" .. "}"
        local configParameter = configParameter1 .. configParameter2 ..
                                    configParameter3
        -- info参数
        local clientNo, city, typeId, orgId = info[1], info[2], info[3], info[4]
        local infoParameter =
            "{" .. "\"city\"" .. ":" .. "\"" .. tostring(city) .. "\"" .. "," ..
                "\"clientNo\"" .. ":" .. "\"" .. clientNo .. "\"" .. "," ..
                "\"typeId\"" .. ":" .. "\"" .. tostring(typeId) .. "\"" .. "," ..
                "\"orgId\"" .. ":" .. "\"" .. tostring(orgId) .. "\"" .. "}"
        -- centerconfig参数
        local ip, license, owner, type, groupId, clientId, uname, pwd, scope,
              mqtthost, topic, eqrTopic, answerTopic, port, ftpEnable, ftpHost,
              ftpPort, ftpName, ftpPsw, contentType, enableVerify, authServer,
              mckParams, caParams = centerConfig[1], centerConfig[2],
                                    centerConfig[3], centerConfig[4],
                                    centerConfig[5], centerConfig[6],
                                    centerConfig[7], centerConfig[8],
                                    centerConfig[9], centerConfig[10],
                                    centerConfig[11], centerConfig[12],
                                    centerConfig[13], centerConfig[14],
                                    centerConfig[15], centerConfig[16],
                                    centerConfig[17], centerConfig[18],
                                    centerConfig[19], centerConfig[20],
                                    centerConfig[21], centerConfig[22],
                                    centerConfig[23], centerConfig[24]

        if authServer == nil then authServer = "" end
        if contentType == nil then contentType = " " end
        if mckParams == nil then mckParams = "" end
        if caParams == nil then caParams = " " end
        log.info("pwd", pwd, "contentType", contentType)
        if pwd == nil then pwd = "" end
        if groupId == nil then groupId = "" end
        if uname == nil then uname = "" end
        if clientId == nil then clientId = "" end
        log.info("eqrTopic", eqrTopic)
        local sendMsg =
            "{\"todo\":\"writeConfig\",\"centerConfig\":{\"owner\":\"" .. owner ..
                "\",\"answerTopic\":\"" .. answerTopic .. "\",\"clientId\":\"" ..
                clientId .. "\",\"uname\":\"" .. uname .. "\",\"ftpEnable\":\"" ..
                ftpEnable .. "\",\"ip\":\"" .. ip .. "\",\"groupId\":\"" ..
                groupId .. "\",\"mqtthost\":\"" .. mqtthost .. "\",\"type\":\"" ..
                type .. "\",\"ftpHost\":\"" .. ftpHost .. "\",\"license\":\"" ..
                license .. "\",\"ftpName\":\"" .. ftpName .. "\",\"port\":\"" ..
                tostring(port) .. "\",\"scope\":\"" .. scope ..
                "\",\"ftpPsw\":\"" .. ftpPsw .. "\",\"topic\":\"" .. topic ..
                "\",\"eqrTopic\":\"" .. eqrTopic .. "\",\"pwd\":\"" .. pwd ..
                "\",\"ftpPort\":\"" .. tostring(ftpPort) ..
                "\",\"contentType\":\"" .. contentType ..
                "\",\"enableVerify\":\"" .. enableVerify ..
                "\",\"authServer\":\"" .. authServer .. "\",\"mckParams\":\"" ..
                mckParams .. "\",\"caParams\":\"" .. caParams .. "\"" ..
                "},\"config\":" .. configParameter .. ",\"info\":" ..
                infoParameter .. "}"
        log.info("sendMsg", sendMsg)
        local topicSendMqtt = "action"
        sendMsg =
            crypto.aes_encrypt("ECB", "PKCS5", sendMsg, "keson-123abcdefg")
        sendMsg = crypto.base64_encode(sendMsg, slen(sendMsg))
        mqttOutMsg.insertMsg(topicSendMqtt, sendMsg, 0)
        return true
    end
end

-- 存储系统参数
function saveParameters(tjsondata)
    local clients = tjsondata["clients"]
    -- 系统参数
    if containClientsOrNot(clients) then
        local config, info, centerConfig = tjsondata["config"],
                                           tjsondata["info"],
                                           tjsondata["centerConfig"]
        local appName, version, longitude, latitude, cloud, lock, openTime,
              closeTime, updateUrl, versionUrl, broker, ntpServer, delayTime,
              centerName, intensity, magnitude, centerIntensity, countDown,
              alertSound, alertLight, emergencyLamp, relay, adVolume,
              alertVolume, intensityReturn, adUpdateUrl, orgName, makeVideo,
              uploadVideoUrl, broadcast, broadcastUrl, h24, enable433,
              autoUpdateLog, alertDisplayMode, color1, color2, color3, color4,
              luminance, hz, autoCheckTime, regCenter, lockPsw, receive,
              replayLockPsw, enableRF433, enableAcc, enableTF, enableHandset,
              hideBattery, brightnessPositive, clientName, updateRate, memsIp,
              stations, move, rotate, enableRealKey, blueLimit, yellowLimit,
              orangeLimit, redLimit, afterSecond, sourceText, blueGuide,
              yellowGuide, orangeGuide, redGuide, exerciseText, enableMax10,
              cancelCount, fastCount, carouselCount, master, masterPair =
            config["appName"], config["version"], config["longitude"],
            config["latitude"], config["cloud"], config["lock"],
            config["openTime"], config["closeTime"], config["updateUrl"],
            config["versionUrl"], config["broker"], config["ntpServer"],
            config["delayTime"], config["centerName"], config["intensity"],
            config["magnitude"], config["centerIntensity"], config["countDown"],
            config["alertSound"], config["alertLight"], config["emergencyLamp"],
            config["relay"], config["adVolume"], config["alertVolume"],
            config["intensityReturn"], config["adUpdateUrl"], config["orgName"],
            config["makeVideo"], config["uploadVideoUrl"], config["broadcast"],
            config["broadcastUrl"], config["h24"], config["enable433"],
            config["autoUpdateLog"], config["alertDisplayMode"],
            config["color1"], config["color2"], config["color3"],
            config["color4"], config["luminance"], config["hz"],
            config["autoCheckTime"], config["regCenter"], config["lockPsw"],
            config["receive"], config["replayLockPsw"], config["enableRF433"],
            config["enableAcc"], config["enableTF"], config["enableHandset"],
            config["hideBattery"], config["brightnessPositive"],
            config["clientName"], config["updateRate"], config["memsIp"],
            config["stations"], config["move"], config["rotate"],
            config["enableRealKey"], config["blueLimit"], config["yellowLimit"],
            config["orangeLimit"], config["redLimit"], config["afterSecond"],
            config["sourceText"], config["blueGuide"], config["yellowGuide"],
            config["orangeGuide"], config["redGuide"], config["exerciseText"],
            config["enableMax10"], config["cancelCount"], config["fastCount"],
            config["carouselCount"], config["master"], config["masterPair"]
        local clientNo, city, typeId, orgId = info["clientNo"], info["city"],
                                              info["typeId"], info["orgId"]
        log.info("info", info)
        -- 中心配置参数
        local ip, license, owner, type, groupId, clientId, uname, pwd, scope,
              mqtthost, topic, eqrTopic, answerTopic, port, ftpEnable, ftpHost,
              ftpPort, ftpName, ftpPsw, contentType, enableVerify, authServer,
              mckParams, caParams = centerConfig["ip"], centerConfig["license"],
                                    centerConfig["owner"], centerConfig["type"],
                                    centerConfig["groupId"],
                                    centerConfig["clientId"],
                                    centerConfig["uname"], centerConfig["pwd"],
                                    centerConfig["scope"],
                                    centerConfig["mqtthost"],
                                    centerConfig["topic"],
                                    centerConfig["eqrTopic"],
                                    centerConfig["answerTopic"],
                                    centerConfig["port"],
                                    centerConfig["ftpEnable"],
                                    centerConfig["ftpHost"],
                                    centerConfig["ftpPort"],
                                    centerConfig["ftpName"],
                                    centerConfig["ftpPsw"],
                                    centerConfig["contentType"],
                                    centerConfig["enableVerify"],
                                    centerConfig["authServer"],
                                    centerConfig["mckParams"],
                                    centerConfig["caParams"]
        nvm.set("appName", appName, nil, false)
        nvm.set("version", version, nil, false)
        nvm.set("longitude", longitude, nil, false)
        nvm.set("latitude", latitude, nil, false)
        nvm.set("cloud", cloud, nil, false)
        nvm.set("lock", lock, nil, false)
        nvm.set("openTime", openTime, nil, false)
        nvm.set("closeTime", closeTime, nil, false)
        nvm.set("updateUrl", updateUrl, nil, false)
        nvm.set("versionUrl", versionUrl, nil, false)
        nvm.set("broker", broker, nil, false)
        nvm.set("ntpServer", ntpServer, nil, false)
        nvm.set("delayTime", delayTime, nil, false)
        nvm.set("centerName", centerName, nil, false)
        nvm.set("intensity", intensity, nil, false)
        nvm.set("magnitude", magnitude)
        nvm.set("centerIntensity", centerIntensity, nil, false)
        nvm.set("countDown", countDown, nil, false)
        nvm.set("alertSound", alertSound, nil, false)
        nvm.set("alertLight", alertLight, nil, false)
        nvm.set("emergencyLamp", emergencyLamp, nil, false)
        nvm.set("relay", relay, nil, false)
        nvm.set("adVolume", adVolume, nil, false)
        nvm.set("alertVolume", alertVolume, nil, false)
        nvm.set("intensityReturn", intensityReturn, nil, false)
        nvm.set("adUpdateUrl", adUpdateUrl, nil, false)
        nvm.set("orgName", orgName, nil, false)
        nvm.set("makeVideo", makeVideo, nil, false)
        nvm.set("uploadVideoUrl", uploadVideoUrl, nil, false)
        nvm.set("broadcast", broadcast, nil, false)
        nvm.set("broadcastUrl", broadcastUrl, nil, false)
        nvm.set("h24", h24, nil, false)
        nvm.set("enable433", enable433, nil, false)
        nvm.set("autoUpdateLog", autoUpdateLog, nil, false)
        nvm.set("alertDisplayMode", alertDisplayMode, nil, false)
        nvm.set("color1", color1, nil, false)
        nvm.set("color2", color2, nil, false)
        nvm.set("color3", color3, nil, false)
        nvm.set("color4", color4, nil, false)
        nvm.set("luminance", luminance, nil, false)
        nvm.set("hz", hz, nil, false)
        nvm.set("autoCheckTime", autoCheckTime, nil, false)
        nvm.set("regCenter", regCenter, nil, false)
        nvm.set("lockPsw", lockPsw, nil, false)
        nvm.set("receive", receive, nil, false)
        nvm.set("replayLockPsw", replayLockPsw, nil, false)
        nvm.set("enableRF433", enableRF433, nil, false)
        nvm.set("enableAcc", enableAcc, nil, false)
        nvm.set("enableTF", enableTF, nil, false)
        nvm.set("enableHandset", enableHandset, nil, false)
        nvm.set("hideBattery", hideBattery, nil, false)
        nvm.set("enableRealKey", enableRealKey, nil, false)
        nvm.set("brightnessPositive", brightnessPositive, nil, false)
        nvm.set("clientName", clientName, nil, false)
        nvm.set("updateRate", updateRate, nil, false)
        nvm.set("memsIp", memsIp, nil, false)
        nvm.set("stations", stations, nil, false)
        nvm.set("move", move, nil, false)
        nvm.set("rotate", rotate, nil, false)
        nvm.set("blueLimit", blueLimit, nil, false)
        nvm.set("yellowLimit", yellowLimit, nil, false)
        nvm.set("orangeLimit", orangeLimit, nil, false)
        nvm.set("redLimit", redLimit, nil, false)
        nvm.set("afterSecond", afterSecond, nil, false)
        nvm.set("sourceText", sourceText, nil, false)
        nvm.set("blueGuide", blueGuide, nil, false)
        nvm.set("yellowGuide", yellowGuide, nil, false)
        nvm.set("orangeGuide", orangeGuide, nil, false)
        nvm.set("redGuide", redGuide, nil, false)
        nvm.set("exerciseText", exerciseText, nil, false)
        nvm.set("enableMax10", enableMax10, nil, false)
        nvm.set("cancelCount", cancelCount, nil, false)
        nvm.set("fastCount", fastCount, nil, false)
        nvm.set("carouselCount", carouselCount, nil, false)
        nvm.set("master", master, nil, false)
        nvm.set("masterPair", masterPair, nil, false)
        nvm.set("info", {clientNo, city, typeId, orgId}, nil, false)
        nvm.set("centerConfig", {
            ip, license, owner, type, groupId, clientId, uname, pwd, scope,
            mqtthost, topic, eqrTopic, answerTopic, port, ftpEnable, ftpHost,
            ftpPort, ftpName, ftpPsw, contentType, enableVerify, authServer,
            mckParams, caParams
        })
    end
    logInfo = logInfo .. "[" .. sysTime .. "]" ..
                  "[存储设备参数:]成功!\n"
    sys.restart("远程保存参数设置，重启使之生效！")
    logInfo = logInfo .. "[" .. sysTime .. "]" ..
                  "[设备重启:]重启成功，参数设置生效!\n"
    if logInfo ~= nil and logInfo ~= false then
        logGenerator.generateLogTask(logInfo, "log")
    end
end
